class DoofinderAddToCartError extends Error{constructor(e,a=""){const i="Error adding an item to the cart. Reason: "+e+". Status code: "+a;super(i),this.name="DoofinderAddToCartError"}}document.addEventListener("doofinder.cart.add",function(s){const e=s.detail,a=e.amount,i=e.statusPromise;let c=e.item_id,r=e.grouping_id&&e.grouping_id===e.item_id&&e.group_leader;if(e.modifiable||r){i.reject(new DoofinderAddToCartError("It's a configurable product",200)),location.href=e.link;return}let o=e.gtin?e.gtin:null,t=new XMLHttpRequest;t.onreadystatechange=function(){if(this.readyState===4&&this.status===200){let n=document.getElementsByClassName("cart-quantity");n.length&&(n[0].innerHTML++,n[0].classList.add("countPill--positive")),i.resolve("The item has been successfully added to the cart.")}else if(this.readyState===4){const n=this.statusMessage||"Unknown";i.reject(new DoofinderAddToCartError(n,this.status))}},o?t.open("GET",`/cart.php?action=add&sku=${encodeURIComponent(o)}&qty=${a}`):t.open("GET",`/cart.php?action=add&product_id=${c}&qty=${a}`),t.send()}),function(){let s=null;async function e(){if(s){const[,t]=s.split("."),{exp:n}=JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")));if(n*1e3>Date.now()+6e4)return s}const{platformAppKey:c}=Doofinder.getConfig(),r=await fetch("/customer/current.jwt?app_client_id="+c),o=await r.text();if(!r.ok||o.split(".").length!==3){let t;try{t=JSON.parse(o)?.errors?.[0]?.detail}catch{}throw new Error(t??"Failed to fetch customer JWT: "+r.status)}return s=o,o}async function a(c,r,o){const{zone:t}=Doofinder.getConfig(),n=`https://${t}-plugins.doofinder.com/bigcommerce/contextual-prices`;return(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jwt:r,products:c,channel_id:dfChannelId,currency:dfCurrencyCode}),signal:o})).json()}async function i(c,r){if(typeof DoofinderContextualPrices>"u")return;const o=DoofinderContextualPrices.getCards();if(o.length){DoofinderContextualPrices.hidePrices(o);try{const t=[...new Set(o.map(u=>u.dataset.productId))],n=await e(),d=await a(t,n,r);DoofinderContextualPrices.updatePrices(o,d)}catch(t){t.name!=="AbortError"&&console.error("Failed to fetch contextual prices:",t)}finally{DoofinderContextualPrices.showPrices(o)}}}dfGroupId>0&&typeof DoofinderContextualPrices<"u"&&DoofinderContextualPrices.onUpdate(i)}();